<template>
  <div class="publish">
    <cldPostForm v-model:value="newPostForm"></cldPostForm>
    <div class="action">
      <span class="pub ab" @click="sendPublishOrSavePost(1)"
        >发布</span
      >
      <span class="save ab" @click="sendPublishOrSavePost(2)"
        >保存草稿</span
      >
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { FileResult } from "~/api/file";
import { SendNewPostParams } from "~/api/post/types";
import { fetchSendNewPost } from "~/api/post";
import cldPostForm from "~/components/cld-post-form/index.vue";
const newPostForm = ref<SendNewPostParams>({
  community_id: "1",
  content: "",
  status: 1,
  title: "",
  cover: "",
  description: "",
});
const sendPublishOrSavePost = (type: number) => {
  newPostForm.value.status = type;
  fetchSendNewPost(newPostForm.value).then((r) => {
    if (r.code === 1000) {
      window.NMessage.success(
        type === 1 ? "发布成功！快去查看吧！" : "已经存入草稿箱啦！"
      );
    }
  });
};
</script>
<style lang="scss" scoped>
.publish {
  .action {
    display: flex;
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    .ab{
      padding: 5px;
      margin: 10px;
      border-radius: 5px;
      box-shadow: 1px 1px 1px #000;
    }
    .pub {
      background-color: greenyellow;
    }
    .save {
      background-color: rgb(85, 117, 244);
      color: #fff;
    }
  }
}
</style>
